<template>
	<view>
		<view class="form">
			<view class="item">
				<view class="lable">昵称</view>
				<view class="text">
					<input v-model="userInfo.nickName" placeholder="请输入昵称" />
				</view>
			</view>
			<view class="item">
				<view class="lable">手机号码</view>
				<view class="text">
					<input v-model="userInfo.phonenumber" placeholder="请输入手机号码" />
				</view>
			</view>
			<view class="item">
				<view class="lable">邮箱</view>
				<view class="text">
					<input v-model="userInfo.email" placeholder="请输入邮箱" />
				</view>
			</view>
			<view class="item">
				<view class="lable">性别</view>
				<view class="text">
					<input v-model="userInfo.sex" placeholder="请输入性别" />
				</view>
			</view>
		</view>
		<view class="updata">
			<button type="primary" @click="updata()">确认修改</button>
			<button @click="goBack()">返回</button>
		</view>
	</view>
</template>

<script>
	import '../profile.scss'
	import {
		getUserProfile,
		updateUserInfo
	} from '@/api/system/user'

	export default {
		components: {},
		data() {
			return {
				userInfo: {
					nickName: "",
					phonenumber: "",
					email: "",
					sex: ""
				}
			}
		},
		created() {
			this.getInfo()
		},
		methods: {
			getInfo() {
				const app = this
				getUserProfile().then(result => {
					app.userInfo = result.data.data
				})
			},
			radioChange(e) {
				this.userInfo.sex = e.detail.value
			},
			updata() {
				const app = this
				updateUserInfo(app.userInfo).then(result => {
					if (result.data.code == 200) {
						this.$showToast('修改成功', 'success', 2000);
					} else {
						this.$showToast(result.data.msg, 'error', 2000);
					}
				})
			},
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '../profile.scss';
</style>